package com.ifengxue.ioc.bean;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;

/**
 * bean工厂
 */
public interface BeanFactory {
    /**
     * 检查bean是否存在
     * @param name
     * @return
     */
    default boolean containsBean(@Nonnull String name) {
        return Optional.ofNullable(getBean(name)).isPresent();
    }

    /**
     * 获取指定的bean实例
     * @param requiredType
     * @param <T>
     * @return
     */
    @Nullable
    <T> T getBean(@Nonnull Class<T> requiredType);

    /**
     * 获取指定的bean实例
     * @param name
     * @return
     */
    @Nullable
    Object getBean(@Nonnull String name);

    /**
     * 检查是否是单例bean
     * @param name
     * @return
     */
    boolean isSingleton(String name) throws BeanNotFoundException;

    /**
     * 检查是否是原型bean
     * @param name
     * @return
     */
    boolean isPrototype(String name) throws BeanNotFoundException;
}
